<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        ul {
            list-style: none;
        }

        .box {
            width: 300px;
            padding: 0 20px;
            margin: 20px auto;
            border: 2px solid lightblue;
        }

        .box li {
            line-height: 35px;
            border-bottom: 1px dashed orange;
        }

        .box li:last-child {
            border-bottom: none;
        }
    </style>
</head>

<body>
    <ul class="box">
        <li>我是第一个</li>
        <li>我是第二个</li>
        <li>我是第三个</li>
        <li>我是第四个</li>
        <li>我是第五个</li>
    </ul>
    <script>
        let lis = document.querySelectorAll('li')
        for (var i = 0; i < lis.length; i++) {
            if (i % 2 == 0) {
                lis[i].style.backgroundColor = 'white'
                lis[i].myData = 'white'
            } else {
                lis[i].style.backgroundColor = 'pink'
                lis[i].myData = 'pink'
            }
            lis[i].onmouseover = function () {
                this.style.backgroundColor = 'red'
            }
            lis[i].onmouseout = function () {
                this.style.backgroundColor = this.myData
            }
        }
    </script>
</body>

</html>